package com.github.shuaidd.service.editor;

import lombok.AllArgsConstructor;
import org.activiti.app.domain.editor.Model;
import org.activiti.engine.identity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
@AllArgsConstructor(onConstructor_ = {@Autowired})
public class AppDefinitionPublishService {

  private final LwfModelService modelService;
  private final LwfDeploymentService deploymentService;

  public void publishAppDefinition(String comment, Model appDefinitionModel, User user) {

    // Create new version of the app model
    modelService.createNewModelVersion(appDefinitionModel, comment, user);

    // Deploy the app model to be executable
    deploymentService.updateAppDefinition(appDefinitionModel, user);
  }

}
